package com.sangmo.fts.training.calculator;

import com.sangmo.boot.framework.common.utils.ApplicationUtils;
import com.sangmo.boot.framework.data.json.context.KeyValue;
import com.sangmo.boot.framework.data.json.load.Calculator;
import com.sangmo.fts.training.vo.UserRankView;
import com.sangmo.fts.training.model.Score;
import com.sangmo.fts.training.service.ScoreEntityService;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class ScoreRankingCalculator implements Calculator<Score>, Score.IRankingCalculator {


    @Override
    public Object calc(Score bean, Collection<KeyValue> exts) {

        ScoreEntityService scoreEntityService = ApplicationUtils.getBean(ScoreEntityService.class);
        UserRankView result = scoreEntityService.findRankingByExaminationIdAndUserId(bean.getUserId(), bean.getExaminationId());

        return result.getRanking();
    }
}
